using UnityEngine;

public class Object_Chest : MonoBehaviour, IDamagable
{
    private Animator animator;
    private Rigidbody2D rb;
    private Entity_VFX chest_VFX;
    private Entity_DropManager dropManager;
    private bool canDrop = true;

    [Header("-----Open Detail-----")]
    [SerializeField] private Vector2 knockBackMovement=new(1,3);
    void Awake()
    {
        animator = GetComponentInChildren<Animator>();
        rb = GetComponent<Rigidbody2D>();
        chest_VFX = GetComponent<Entity_VFX>();
        dropManager = GetComponent<Entity_DropManager>();
    }
    public bool TakeDamage(float damage, float elementalDamage, ElementType elementialType, Transform attacker, bool isCrit)
    {
        //播放宝箱打开动画
        animator.SetBool("OpenChest", true);
        //设置击退时移动速度
        rb.velocity = knockBackMovement;
        //设置随机旋转
        rb.angularVelocity = Random.Range(-50f, 50f);
        //设置受击特效
        chest_VFX.PlayOnDamageVFX();
        if (canDrop)
        {
            dropManager.DropItem();
            canDrop = false;
        }
        return true;
    }
}
